<?php

require_once(_PS_TOOL_DIR_ . 'tcpdf/config/lang/rus.php');
require_once(_PS_TOOL_DIR_ . 'tcpdf/tcpdf.php');

class PdfView {

    protected $_renderer;

    public function __construct($params = array()) {

        $default_params = array(
            'orientation' => P,
            'unit' => 'mm',
            'format' => 'A4',
            'unicode' => TRUE,
            'encoding' => 'UTF-8',
            'disk_cache' => FALSE,
            'pdfa' => FALSE
        );

        $params = array_merge($default_params, $params);

        $this->_renderer = new TCPDF(
                        $params['orientation'], $params['unit'], $params['format'], $params['unicode'], $params['encoding'], $params['disk_cache'], $params['pdfa']
        );
    }

    /**
     *
     * @param Order $order
     */
    public function renderForm116($order) {

        $this->_renderer->SetCreator('RussianPostCarrier for Prestashop');
        $this->_renderer->SetCompression(TRUE);
        $this->_renderer->setPrintHeader(FALSE);
        $this->_renderer->setPrintFooter(FALSE);
        $this->_renderer->AddFont('freeserif');

        $this->_renderer->AddPage();

        $this->_renderer->SetTitle('Форма 116');

        $this->_renderer->Polygon(
                array(
            0, 0, 50, 0, 50, 15, 0, 15
                ), '', '0.2 1', '', TRUE);

        $this->render('form116.pdf');
    }

    public function render($filename, $mode = 'D') {
        $this->_renderer->Output($filename, $mode);
    }

}